<template>
  <div style="background-color:rgb(228,228,228) ; width:100%;height:618px">
    <div style="text-align: center; font-size: 30px; margin-top: 30px;"></div>
    <i class="el-icon-arrow-left" @click="$router.go(-1)"></i>
    <div style="text-align: center; font-size: 22px; margin-top: 5px;">浏览历史</div>

    <div style="margin-top: 20px;">
        <van-swipe-cell v-for="g in goods" :key="g.id">
        <van-card
        :price="g.price"
        :desc="g.description"
        :title="g.name"
        :thumb="g.imgUrl"
        />
            <template #right>
        <van-button square text="删除" @click="deleteLog(g.id)" type="danger" class="delete-button" />
        </template>
        </van-swipe-cell>
     </div>
  </div>

</template>

<script>
import 'vant/lib/index.css';
import { Card,SwipeCell,Button } from 'vant';

export default {
    components: {
    [Card.name]: Card,
    [SwipeCell.name]: SwipeCell,
    [Button.name]: Button,
    
  },
  data(){
        return{
          goods:[],
          id:'',
          goodsLog:[],
        }
        
    },
    methods:{
        queryGoodsLog(){
            let phone =sessionStorage.getItem("phone");
            this.$axios.get('api/app/GoodsLog/queryGoodsLog?phone='+phone)
            .then(res=>{
                console.log(res.data)
                if(res.data.code == 200){
                    this.goods = res.data.data
                }
            })
        },
        deleteLog(id){
          console.log(id);
            let goodsLog = {};
            goodsLog.goodsId=id;
            goodsLog.phone = sessionStorage.getItem("phone");
            
            this.$axios.post('api/app/GoodsLog/deleteGoodsLog',goodsLog)
            .then(res=>{
                console.log(res.data)
                if(res.data.code == 200){
                    this.$message("删除成功！")
                    this.queryGoodsLog();
                } else{
                    this.$message("删除失败！")
                }
            })
        }

    },
    created(){
            this.queryGoodsLog();
            
        }
}
</script>

<style scoped>
.van-button--square{
    height: 100%;
}
</style>